package com.ruoyi.project.gxgw_modules.level.service;

import com.ruoyi.common.support.Convert;
import com.ruoyi.common.utils.security.ShiroUtils;
import com.ruoyi.project.gxgw_modules.level.domain.Level;
import com.ruoyi.project.gxgw_modules.level.mapper.LevelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;

/**
 * 会员等级 服务层实现
 *
 * @author ruoyi
 * @date 2019-01-19
 */
@Service
public class LevelServiceImpl implements ILevelService {

    @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection")
    @Autowired
    private LevelMapper levelMapper;

    @Override
    public boolean selectIfIdForVip(String idForVip) {

        String[] idForVips = Convert.toStrArray(idForVip);

        for (int i = 0; i < idForVips.length; i++) {

            if (levelMapper.selectIfIdForVip(Integer.parseInt(idForVips[i])) > 0) {

                return true;
            }

        }
        return false;
    }

    /**
     * 查询会员等级信息
     *
     * @param levelId 会员等级ID
     * @return 会员等级信息
     */
    @Override
    public Level selectLevelById(Integer levelId) {
        return levelMapper.selectLevelById(levelId);
    }

    /**
     * 查询会员等级列表
     *
     * @param level 会员等级信息
     * @return 会员等级集合
     */
    @Override
    public List<Level> selectLevelList(Level level) {
        return levelMapper.selectLevelList(level);
    }

    /**
     * 新增会员等级
     *
     * @param level 会员等级信息
     * @return 结果
     */
    @Override
    public int insertLevel(Level level) {
        level.setCreateBy(ShiroUtils.getSysUser().getUserName());
        level.setCreateTime(new Timestamp(new Date().getTime()));
        return levelMapper.insertLevel(level);
    }

    /**
     * 修改会员等级
     *
     * @param level 会员等级信息
     * @return 结果
     */
    @Override
    public int updateLevel(Level level) {
        level.setUpdateBy(ShiroUtils.getSysUser().getUserName());
        level.setUpdateTime(new Timestamp(new Date().getTime()));
        return levelMapper.updateLevel(level);
    }

    /**
     * 删除会员等级对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteLevelByIds(String ids) {
        return levelMapper.deleteLevelByIds(Convert.toStrArray(ids));
    }

}
